package com.xjscrm.server.biz.mq.consumer;

import com.alibaba.fastjson.JSONObject;
import com.uzai.mobile.collect.api.MicaTopics;
import com.uzai.mobile.collect.api.dto.MicaTransDto;
import com.uzai.mobile.collect.api.enums.MicaMsgType;
import com.xjscrm.server.biz.mq.hander.ConsumerHandler;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.springframework.stereotype.Component;

/**
 * 企微-基础topic, 主要是心跳, 上线等消息
 *
 * @author JiangHam
 * @date 2024-02-29 16:41
 */
@Slf4j
@RocketMQMessageListener(topic = MicaTopics.WW_BASE_TOPIC, consumerGroup = MicaTopics.WW_BASE_TOPIC)
@Component
public class WwMobileBaseConsumer extends BaseTransMqConsumer {
    @Override
    public void doMessageHandle(MicaTransDto micaTransDto) {
        try {
            log.info("收到消息={}" ,JSONObject.toJSONString(micaTransDto));
            MicaMsgType byValue = MicaMsgType.getByValue(micaTransDto.getMsgType());
            ConsumerHandler consumerHandler = MsgTriggerTaskProcessorHolder.matchProcessor(byValue);
            if (consumerHandler != null) {
                log.info("处理消息={}，micaTransDto={}", byValue.getDesc(), JSONObject.toJSONString(micaTransDto));
                consumerHandler.handle(micaTransDto);
            } else {
                log.info("-没有处理该MQ数据的业务-");
            }
        }catch (Exception e){
            log.error(e.getMessage(), e);
        }
    }
}
